package com.wireless.action;

import java.util.List;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import com.wireless.base.BaseAction;
import com.wireless.entity.Tabletbl;
import com.wireless.service.TableService;

@Namespace("/table")
@ParentPackage("json-default")
@Controller
public class TableAction extends BaseAction {
	private Tabletbl table;
	private String num;
	private List<Tabletbl> tablelist;
	private int tid;
	@Autowired
	private TableService tableService;

	@Action(value = "getTableList", results = { @Result(name = "success", location = "/views/table/table.jsp") })
	public String getTableList() {
		tablelist = tableService.getTableList();
		return SUCCESS;
	}

	@Action(value = "addTable", results = { @Result(name = "success", location = "/views/table/table.jsp") })
	public String addTable() {
		table.setFlag("1");
		System.out.println(table.getNum());
		table.setOrdId(0);
		tableService.addTable(table);
		tablelist = tableService.getTableList();
		return SUCCESS;
	}

	@Action(value = "delTable", results = { @Result(name = "success", location = "/views/table/table.jsp") })
	public String delTable() {
		tableService.delTable(table.getId());
		tablelist = tableService.getTableList();
		return SUCCESS;
	}

	@Action(value = "changeTableFlag", results = { @Result(name = "success", type = "json") })
	public String changeTableFlag() {
		tableService.changeTableFlag(tid);
		return SUCCESS;
	}

	public List<Tabletbl> getTablelist() {
		return tablelist;
	}

	public void setTablelist(List<Tabletbl> tablelist) {
		this.tablelist = tablelist;
	}

	public Tabletbl getTable() {
		return table;
	}

	public void setTable(Tabletbl table) {
		this.table = table;
	}

	public String getNum() {
		return num;
	}

	public void setNum(String num) {
		this.num = num;
	}

	public int getTid() {
		return tid;
	}

	public void setTid(int tid) {
		this.tid = tid;
	}

}
